package com.topcoder.srm184;

public class TeamBuilder {
	public int[] specialLocations(String[] paths) {
		int N = paths.length;
		boolean[][] g = new boolean[N][N];
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				g[i][j] = (i==j) || (paths[i].charAt(j) == '1');
			}
		}
		
		for (int k=0; k<N; k++) {
			for (int i=0; i<N; i++) {
				for (int j=0; j<N; j++) {
					g[i][j] |= g[i][k] & g[k][j];
				}
			}
		}
		
		int rowCount = 0;
		int colCount = 0;
		for (int i=0; i<N; i++) {
			int row = 0;
			int col = 0;
			for (int j=0; j<N; j++) {
				if (g[i][j]) row++;
				if (g[j][i]) col++;
			}
			if (row == N) rowCount++;
			if (col == N) colCount++;
		}
		
		return new int[]{rowCount, colCount};
	}
}
